package com.sniff.atp.modules.test.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sniff.atp.common.api.CommonPage;
import com.sniff.atp.common.api.CommonResult;
import com.sniff.atp.modules.test.model.OpsDeleteSku;
import com.sniff.atp.modules.test.service.OpsDeleteSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  删除商品sku
 * </p>
 *
 * @author macro
 * @since 2023-10-12
 */
@RestController
@RequestMapping("/ops/opsDeleteSku")
@Api(value = "ops删除sku", tags = "ops删除sku")
public class OpsDeleteSkuController {

    @Autowired
    private OpsDeleteSkuService opsDeleteSkuService;

    @ApiOperation("新增删除商品sku")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult create(@RequestBody OpsDeleteSku opsDeleteSku) {
        boolean success = opsDeleteSkuService.create(opsDeleteSku);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("修改删除商品sku")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult update(@RequestBody OpsDeleteSku opsDeleteSku) {

        boolean success = opsDeleteSkuService.update(opsDeleteSku.getSkuDeleteId(), opsDeleteSku);
        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("根据ID获取详情")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    @ResponseBody
    public CommonResult<OpsDeleteSku> getItem(@PathVariable Long id) {
        OpsDeleteSku opsDeleteSku = opsDeleteSkuService.getById(id);
        return CommonResult.success(opsDeleteSku);
    }

    @ApiOperation("根据ID删除问题列表")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult delete(@PathVariable Long id) {
        boolean success = opsDeleteSkuService.removeById(id);

        if (success) {
            return CommonResult.success(null);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("分页查询问题")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<CommonPage<OpsDeleteSku>> list(@RequestBody OpsDeleteSku opsDeleteSku) {
        if(opsDeleteSku.getPageSize() == null){
            opsDeleteSku.setPageSize(10);
        }
        if(opsDeleteSku.getPageNum() == null){
            opsDeleteSku.setPageNum(1);
        }
        Page<OpsDeleteSku> menuList = opsDeleteSkuService.list(opsDeleteSku, opsDeleteSku.getPageSize(), opsDeleteSku.getPageNum());
        return CommonResult.success(CommonPage.restPage(menuList));
    }
}

